package com.gorkr.labuladong.data_struct.array;

/**
 * @author gorkr
 * @date 2022/06/03 11:37
 **/
public class M167TwoSumIIInputArrayIsSorted {

    public int[] twoSum(int[] numbers, int target) {

        int left = 0, right = numbers.length - 1;
        while (left < right) {
            int sum = numbers[left] + numbers[right];
            if (sum == target) {
                return new int[]{left + 1, right + 1};
            } else if (sum < target) {
                left++;
            } else if (sum > target) {
                right--;
            }
        }
        return null;
    }
}
    